package cn.zhz.dao;

import cn.zhz.pojo.User;
import org.hibernate.Query;

import java.io.Serializable;
import java.util.List;


public class UserDao extends BaseDao{
    public User get(Serializable id){
        return (User)currentSession().get(User.class,id);
    }
    public void save(User user){
        currentSession().save(user);
    }
    public User load(Serializable id){
        return (User)currentSession().load(User.class,id);
    }
    public void delete(User user){
        currentSession().delete(user);
    }
    public User merge(User user){
        return (User)currentSession().merge(user);
    }
    public void saveOrUpdate(User user){
        currentSession().saveOrUpdate(user);
    }

    public List<User> getAll(){
        String hql = "from User where userName = 'bdqn'";
        Query query = currentSession().createQuery(hql);
        return query.list();
    }

    public List<User> findByPage(int pageNo,int pageSize){
        return currentSession().createQuery("from User order by id")
                .setFirstResult((pageNo-1)*pageSize)
                .setMaxResults(pageSize).list();
    }
}
